2.1 Parsing

When the text in the input area is processed, it's passed to a component known as a parser to internalize the text. If the parser can process the text successfully, the internal form is used to render the “chalkboard” form of the expression on the display and also to reverse-engineer a text form back to the output area. The process is shown in Figure 2.1. The figure also shows the relationship between the text-input area, the parser, the display and the text-output area.

Figure 2.1 Parsing

Parsers are used to recognize sentential forms according to a set of rules, known as a grammar, which collectively define the syntax of a language. Most mathematical expressions are described by simple rules, but some – particularly those that have an unusual display form – have a syntax that is not so simple. If input text is not in the correct form, i.e. does not adhere to the grammar, the parser presents an error message that diagnoses the problem and hopefully points the way to a correction.

Often, the displayed expression bears no resemblance to the input form. This is because for centuries mathematicians have worked with two-dimensional analogue displays (paper and chalkboard) and have produced two-dimensional notations. Because Myron's grammar linearizes two-dimensional notation, its rules can sometimes be non intuitive. One way to learn the grammar is to copy expressions from this guide to the workspace and observe the linearized form in the output area of the display. Then copy the output area to the input area and make changes to achieve particular expression requirements.

Another way to learn Myron's grammar is to refer to the grammar rules. These are described by syntax diagrams based on recursive transition network (RTN) diagrams. The diagrams provide a visual specification of alternative forms of expression. There is an initial diagram (Figure 2.2) from which any expression in the language can be derived.

Figure 2.2 Initial syntax diagram

Each RTN diagram has an entry point and an exit point. A diagram describes possible paths between the entry and exit points by traversing a sequence of entities in the diagram. These entities are enclosed in rectangular borders or round-corner borders. Round-corner borders represent symbols entered from the keyboard, like variables, values and operators. Rectangular borders denote other RTN diagrams which must be traversed recursively. That is, sub diagrams are traversed by suspending traversal of the current diagram, traversing the referenced diagram (and any diagrams referenced by it), and resuming traversal of the suspended diagram. The sequence of symbols encountered in a traversal represents a string that could be parsed into a valid sentence in the language described by the grammar.

The initial diagram for Myron is shown in Figure 2.2. Traversing the diagram requires traversing one of the other diagrams. The diagram says that a principal – the name used to refer to one of a small number of top-level expressions – is one of several entities: an expression, a definition, a transform, a paragraph or a property list. If the intent is to enter an expression, for example, the next symbol entered from the keyboard has to match the first symbol encountered while traversing the diagram labeled "expression".

Moving down a level, Figures 2.3, 2.27, 3.2, 2.50 and 2.52 contain the syntax diagrams referenced in the main diagram. The first symbol of an expression is the first symbol of an operand (Figure 2.5). In turn, the first symbol of an operand is that of a variable, a value, a bracketed expression and so on.

Figure 2.3 Expression